package ESP.Control.A;
/**
 * 角色分配
 */
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import ESP.Dao.BaseDao;

import com.alibaba.fastjson.JSONArray;

public class a03 {
	
	@Resource
	public BaseDao baseDao;
	/**
	 * 返回信息
	 */
	private JSONArray rows;
	private Map<String, String> message = new HashMap<String, String>();
	/**
	 * 用户信息
	 */
	private String user_role_id;
	private String user_id;
	/**
	 * 查询
	 */
	private String stu_id;
	private String stu_name;//姓名
	private String stu_role_id;//角色id
	private String stu_major_id;//专业
	private String stu_faculty_id;//学院id
	private String stu_grade;//年级
	private String stu_class;//班级
	private String stu_groupstate;//是否分组
	/**
	 * 校验
	 */
	private String stu_group_id;
	/**
	 * 查询//适合所有角色
	 */
	public String queryStudent(){
		List list = baseDao.queryStudentByRole(user_id, user_role_id,
				stu_id, stu_name, stu_role_id, stu_major_id, stu_faculty_id, stu_grade, stu_class, stu_groupstate);
		if (list.size() == 0 || list == null) {
			baseDao.setReturnInfo(message, "N", "查询完毕,没有符合条件的数据!");
		}else {
			baseDao.setReturnInfo(message, "Y", "查询完毕,共"+list.size()+"条数据!");
		}
		this.rows = baseDao.toJson(list);
		return "a03_rows";
	}
	/**
	 * 清除学生的选组信息->将小组置为null
	 */
	public String clearGroup(){
		int i = 0;
		i = baseDao.clearGroupInfo(stu_id);
		if (i == 1) {
			baseDao.setReturnInfo(message, "Y", "清除选组信息成功!");
		}else {
			baseDao.setReturnInfo(message, "N", "清除选组信息失败!");
		}
		return "a03_msg";
	}
	/**
	 * 分配角色
	 */
	public String confirmRole(){
		if (user_role_id == null || user_role_id.trim().equals("")) {
			baseDao.setReturnInfo(message, "N", "本次登录会话失效!请重新登录");
			return "a03_msg";
		}
		int i = 0;
		i = baseDao.confirmRole(stu_id, stu_role_id);
		if (i == 1) {
			baseDao.setReturnInfo(message, "Y", "角色分配成功!");
		}else {
			baseDao.setReturnInfo(message, "N", "角色分配失败!");
		}
		return "a03_msg";
	}
	/**
	 * 校验该组是否存在组长
	 */
	public String checkHaveGroupLeader(){
		if (user_role_id == null || user_role_id.equals("")) {
			baseDao.setReturnInfo(message, "N", "此次登录会话失效,请重新登录!");
			return "a03_msg";
		}
		int i = 0;
		i = baseDao.checkGroupHaveLeader(stu_group_id);
		if (i == 1) {
			baseDao.setReturnInfo(message, "N", stu_group_id+"小组已经选过组长!");
		}else {
			baseDao.setReturnInfo(message, "Y", stu_group_id+"还未选定组长!");
		}
		return "a03_msg";
	}
	/**
	 * 校验学委是否存在(年级 学院 专业 班级 指定)
	 */
	public String checkHaveLeaderSuper(){
		if (user_role_id == null || user_role_id.equals("")) {
			baseDao.setReturnInfo(message, "N", "此次登录会话失效,请重新登录!");
			return "a03_msg";
		}
		Map map ;
		map = baseDao.checkHaveXuewei(stu_grade, stu_faculty_id, stu_major_id, stu_class);
		if (map.size() == 0 || map.isEmpty() || map == null) {
			baseDao.setReturnInfo(message, "Y", "学委还未选定!");
		}else {
			baseDao.setReturnInfo(message, "N", "该班级已经选定了学委!");
		}
		return "a03_msg";
	}
	/**
	 * 接上方法-如果学委存在，则清空学委角色。
	 */
	public String clearXuewei(){
		int i = 0;
		i = baseDao.clearXuewei(stu_grade, stu_faculty_id, stu_major_id, stu_class);
		if (i == 1) {
			baseDao.setReturnInfo(message, "Y", "已经清空原学委角色!");
		}else {
			baseDao.setReturnInfo(message, "N", "清空原学委信息失败,请稍后重试!");
		}
		return "a03_msg";
	}
	/**
	 * 选组员
	 */
	public String conformTeamMember(){
		int i = baseDao.conformTeamMember(user_id, stu_id);
		if (i == 1) {
			baseDao.setReturnInfo(message, "Y", "分组成功!");
		}else {
			baseDao.setReturnInfo(message, "N", "分组失败,请稍后重试!");
		}
		return "a03_msg";
	}
	/**
	 * get set
	 */
	public BaseDao getBaseDao() {
		return baseDao;
	}
	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}
	public JSONArray getRows() {
		return rows;
	}
	public void setRows(JSONArray rows) {
		this.rows = rows;
	}
	public String getUser_role_id() {
		return user_role_id;
	}
	public void setUser_role_id(String userRoleId) {
		user_role_id = userRoleId;
	}
	public String getUser_id() {
		return user_id;
	}
	public void setUser_id(String userId) {
		user_id = userId;
	}
	public Map<String, String> getMessage() {
		return message;
	}
	public void setMessage(Map<String, String> message) {
		this.message = message;
	}
	public String getStu_id() {
		return stu_id;
	}
	public void setStu_id(String stuId) {
		stu_id = stuId;
	}
	public String getStu_faculty_id() {
		return stu_faculty_id;
	}
	public void setStu_faculty_id(String stuFacultyId) {
		stu_faculty_id = stuFacultyId;
	}
	public String getStu_grade() {
		return stu_grade;
	}
	public void setStu_grade(String stuGrade) {
		stu_grade = stuGrade;
	}
	public String getStu_major_id() {
		return stu_major_id;
	}
	public void setStu_major_id(String stuMajorId) {
		stu_major_id = stuMajorId;
	}
	public String getStu_class() {
		return stu_class;
	}
	public void setStu_class(String stuClass) {
		stu_class = stuClass;
	}
	public String getStu_role_id() {
		return stu_role_id;
	}
	public void setStu_role_id(String stuRoleId) {
		stu_role_id = stuRoleId;
	}
	public String getStu_name() {
		return stu_name;
	}
	public void setStu_name(String stuName) {
		stu_name = stuName;
	}
	public String getStu_groupstate() {
		return stu_groupstate;
	}
	public void setStu_groupstate(String stuGroupstate) {
		stu_groupstate = stuGroupstate;
	}
	public String getStu_group_id() {
		return stu_group_id;
	}
	public void setStu_group_id(String stuGroupId) {
		stu_group_id = stuGroupId;
	}
}
